
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 04/05/2012 00:06:57
-- Generated from EDMX file: H:\C# Projecten\ptp3\ptp3\MySQLModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_peersstatus]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[status] DROP CONSTRAINT [FK_peersstatus];
GO
IF OBJECT_ID(N'[dbo].[FK_torrentsstatus]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[status] DROP CONSTRAINT [FK_torrentsstatus];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[peers]', 'U') IS NOT NULL
    DROP TABLE [dbo].[peers];
GO
IF OBJECT_ID(N'[dbo].[status]', 'U') IS NOT NULL
    DROP TABLE [dbo].[status];
GO
IF OBJECT_ID(N'[dbo].[torrents]', 'U') IS NOT NULL
    DROP TABLE [dbo].[torrents];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'peers'
CREATE TABLE [dbo].[peers] (
    [peer_id] nvarchar(1000)  NOT NULL,
    [compact] nvarchar(1000)  NOT NULL,
    [port] int  NOT NULL,
    [ip] nvarchar(1000)  NOT NULL,
    [no_peer_id] nvarchar(1000)  NOT NULL,
    [trackerid] nvarchar(1000)  NOT NULL,
    [key] nvarchar(1000)  NULL
);
GO

-- Creating table 'status'
CREATE TABLE [dbo].[status] (
    [status_id] int IDENTITY(1,1) NOT NULL,
    [uploaded] int  NOT NULL,
    [downloaded] int  NOT NULL,
    [left] int  NOT NULL,
    [event] nvarchar(1000)  NOT NULL,
    [numwant] int  NOT NULL,
    [peers_peer_id] nvarchar(1000)  NOT NULL,
    [torrents_torrent_id] int  NOT NULL
);
GO

-- Creating table 'torrents'
CREATE TABLE [dbo].[torrents] (
    [torrent_id] int IDENTITY(1,1) NOT NULL,
    [info_hash] nvarchar(1000)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [peer_id] in table 'peers'
ALTER TABLE [dbo].[peers]
ADD CONSTRAINT [PK_peers]
    PRIMARY KEY CLUSTERED ([peer_id] ASC);
GO

-- Creating primary key on [status_id] in table 'status'
ALTER TABLE [dbo].[status]
ADD CONSTRAINT [PK_status]
    PRIMARY KEY CLUSTERED ([status_id] ASC);
GO

-- Creating primary key on [torrent_id] in table 'torrents'
ALTER TABLE [dbo].[torrents]
ADD CONSTRAINT [PK_torrents]
    PRIMARY KEY CLUSTERED ([torrent_id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [peers_peer_id] in table 'status'
ALTER TABLE [dbo].[status]
ADD CONSTRAINT [FK_peersstatus]
    FOREIGN KEY ([peers_peer_id])
    REFERENCES [dbo].[peers]
        ([peer_id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_peersstatus'
CREATE INDEX [IX_FK_peersstatus]
ON [dbo].[status]
    ([peers_peer_id]);
GO

-- Creating foreign key on [torrents_torrent_id] in table 'status'
ALTER TABLE [dbo].[status]
ADD CONSTRAINT [FK_torrentsstatus]
    FOREIGN KEY ([torrents_torrent_id])
    REFERENCES [dbo].[torrents]
        ([torrent_id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_torrentsstatus'
CREATE INDEX [IX_FK_torrentsstatus]
ON [dbo].[status]
    ([torrents_torrent_id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------